$(document).ready(function() {
    function isIE() {
        var userAgent = navigator.userAgent;
        if (!!window.ActiveXObject || "ActiveXObject" in window) {
            return 1;
        } else {
            return 0;
        }
    }
    IE = isIE();
    var mySwiperBanner = new Swiper('.swiper-container-banner', {
        autoplay: 3000,
        loop: true,
        pagination: '.pagination',
        paginationClickable: true
    });
    var mySwiperSocial = new Swiper('.swiper-container-social', {
        autoplay: 3000,
        loop: true,
        pagination: '.pagination',
        paginationClickable: true
    });
    var mySwiperSocial = new Swiper('.swiper-container-after', {
        loop: true
    });
    var mySwiperSocial = new Swiper('.swiper-container-social-nopage', {
        autoplay: 3000,
        loop: true
    });
    $('.swiper-container-social-after').height($('.swiper-container-social-after .swiper-slide a').height());
    //    console.log($('.swiper-container-social-after .swiper-slide a').height());
    $('.swiper-button-prev').click(function() {
        mySwiperBanner.swipePrev();
    });
    $('.swiper-button-next').click(function() {
        mySwiperBanner.swipeNext();
    });
    //导航条下拉
    // $('.quick1').hover(function() {
    //        console.log('enter');
    // 	$(this).find('.quick').removeClass('hide');
    // }, function() {
    //        console.log('out');
    // 	$(this).find('.quick').addClass('hide');
    // });
    // var menudrowstatus = "1";
    // $(".quick1").mouseenter(function () {
    //     console.log('enter')
    //     menudrowstatus = "1";
    //     setTimeout(function () {
    //         if (menudrowstatus == "0") { return };
    //         $('.quick').stop().slideUp(100).removeClass('hide');
    //         menudrowstatus = "0"
    //     }, 50);
    // });

    // $(".quick1").mouseleave(function () {
    //     console.log('leave')
    //     menudrowstatus = "0";
    //     $('.quick').stop().slideDown(100).addClass('hide');
    // });

    // $('.quick2').hover(function() {
    // 	$(this).find('.quick3').stop().slideUp('400').removeClass('hide');
    // }, function() {
    // 	$(this).find('.quick3').stop().slideDown('400').addClass('hide');
    // });

    //select选择下拉1
    $('.search-dq .search_fill').click(function() {
        if (!($(this).hasClass('active'))) {
            $(this).find('.combo-arrow').css({
                'border-top': 'none',
                'border-bottom': '5px solid #ccc'
            });
            $(this).addClass('active');
            $(this).find('.combo-dropdown').css('display', 'block');

            $(this).parent().siblings().find('.search_fill').removeClass('active');
            $(this).parent().siblings().find('.search_fill').find('.combo-dropdown').css('display', 'none');
            $(this).parent().siblings().find('.search_fill').find('.combo-arrow').css({
                'border-bottom': 'none',
                'border-top': '5px solid #ccc'
            });
            return false;
        } else {
            $(this).removeClass('active');
            $(this).find('.combo-dropdown').css('display', 'none');
            $(this).find('.combo-arrow').css({
                'border-bottom': 'none',
                'border-top': '5px solid #ccc'
            });
        }
    });

    $('.combo-dropdown li').click(function() {
        $(this).addClass('option-selected').siblings().removeClass('option-selected');
        var txt = $(this).html();
        $(this).parent().parent().find('.num').html(txt);
        $(this).parent().next().val($(this).attr('data-value'));
        $(this).parent().parent().removeClass('active');
        $(this).parent().css('display', 'none');
        $(this).parent().prev().css({
            'border-bottom': 'none',
            'border-top': '5px solid #ccc'
        });
        if ($(this).attr('data-type') == 'search') {
            var text = '请输入体检套餐';
            if ($(this).attr('data-value') == 1) {
                text = '请输入体检机构';
            }
            $('input[name=search_key]').attr('placeholder', text);
        }
        return false;

    });
    $(document).click(function() {
        $(".search_fill.active").find('.combo-dropdown').css('display', 'none');
        $(".search_fill.active").find('.combo-arrow').css({
            'border-bottom': 'none',
            'border-top': '5px solid #ccc'
        });
        $(".search_fill.active").removeClass('active');
    });

    //select选择下拉-团检信息填写
    $('.search-dq .search_add').click(function() {
        if (!($(this).hasClass('active'))) {
            $(this).find('.combo-arrow-fill').css({
                'border-top': 'none',
                'border-bottom': '5px solid #ccc'
            });
            $(this).addClass('active');
            $(this).find('.combo-dropdown-fill').css('display', 'block');

            $(this).siblings().removeClass('active');
            $(this).siblings().find('.combo-dropdown-fill').css('display', 'none');
            $(this).siblings().find('.combo-arrow-fill').css({
                'border-bottom': 'none',
                'border-top': '5px solid #ccc'
            });
            return false;
        } else {
            $(this).removeClass('active');
            $(this).find('.combo-dropdown-fill').css('display', 'none');
            $(this).find('.combo-arrow-fill').css({
                'border-bottom': 'none',
                'border-top': '5px solid #ccc'
            });
        }
    });
    $('.search-dq').on('click', '.combo-dropdown-fill li', function() {
        /*$('.combo-dropdown-fill li').click(function(){*/
        var txt = $(this).html();
        $(this).parent().parent().find('.num').html(txt);
        $(this).parent().next().val($(this).attr('data-value'));
        $(this).parent().parent().removeClass('active');
        $(this).parent().css('display', 'none');
        $(this).parent().prev().css({
            'border-bottom': 'none',
            'border-top': '5px solid #ccc'
        });
        var val = $(this).attr("data-value");
        var type = $(this).parent().parent().find('.num').attr('data-type');
        var status = $(this).parent().parent().find('.num').attr('data-status');
        set_select_area(type, status, val);
        return false;
    });
    $(document).click(function() {
        $(".search_add.active").find('.combo-dropdown-fill').css('display', 'none');
        $(".search_add.active").find('.combo-arrow-fill').css({
            'border-bottom': 'none',
            'border-top': '5px solid #ccc'
        });
        $(".search_add.active").removeClass('active');
    });
    /*2016-05-10新增*/
    $('.group_box').click(function() {
        $(".search_add.active").find('.combo-dropdown-fill').css('display', 'none');
        $(".search_add.active").find('.combo-arrow-fill').css({
            'border-bottom': 'none',
            'border-top': '5px solid #ccc'
        });
        $(".search_add.active").removeClass('active');
    });


    $('.content_set .tijian_set .set_name ul li').hover(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var indexset = $(this).index(); //从0开始
        $('.set_list_all_set').find('.set_list').eq(indexset).removeClass('hide').siblings().addClass('hide');
    });
    $('.content_org .tijian_set .set_name ul li').hover(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var indexorg = $(this).index(); //从0开始
        $('.set_list_all_org').find('.set_list').eq(indexorg).removeClass('hide').siblings().addClass('hide');
    });
    $('.content_com .tijian_set .set_name ul li').hover(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var indexorg = $(this).index(); //从0开始
        $('.set_list_all_com').find('.set_list').eq(indexorg).removeClass('hide').siblings().addClass('hide');
    });
    $('.content_after .tijian_set .set_name ul li').hover(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var indexorg = $(this).index(); //从0开始
        $(this).parent().parent().parent().find('.set_list_all_after').find('.set_list').eq(indexorg).removeClass('hide').siblings().addClass('hide');
    });

    //监听滚动
    $(window).scroll(function() {
        if ($(this).scrollTop() >= 179) {
            $('.main_index .navbar').addClass('search_fixed');
        } else {
            $('.main_index .navbar').removeClass('search_fixed');
        }
    });

    $('.world_check .left_right .left').click(function() {
        mySwiperWorld.swipePrev();
    });
    $('.world_check .left_right .right').click(function() {
        mySwiperWorld.swipeNext();
    });

    $('.class_pic_text').hover(function() {
        $(this).find('.class_out').css({
            'display': 'block',
            'transition': 'all 1s'
        });
    }, function() {
        $(this).find('.class_out').css({
            'display': 'none',
            'transition': 'all 1s'
        });
    });
    $('.choose_add ul li a').click(function() {
        $(this).addClass('active');
    });

    $('.choose_select ul li a').hover(function() {
        $(this).find('span').css({
            'background': 'url(/Static/webroot/default/images/select_up1.png) no-repeat'
        });
    }, function() {
        $(this).find('span').css({
            'background': 'url(/Static/webroot/default/images/select_up.png) no-repeat'
        });
    });

    $('.choose_all ul li').click(function() {
        if ($(this).hasClass('active')) {
            $(this).removeClass('active');
            $(this).find('input').checked = false;
        } else {
            $(this).addClass('active');
            $(this).find('input').checked = true;
        }
    });

    //单选按钮
    $('.msg_box .search-dq .sex .sex_radio i').click(function() {
        $(this).parent().addClass('active');
        $(this).parent().siblings().removeClass('active');
        var text = $(this).parent().find('.text').html();
        $(this).parent().parent().find('input').val(text);
    });

    //订单是否多选
    //0表示未选中，1表示选中
    var ifclickmany1;
    var jdk1 = $('.trade_msg_box .dingdan').length;
    $('.shoppingcart .trade_msg_box .dingdan .sex_radio i').click(function() {
        ifclickmany1 = $(this).parent().prev().val();
        if (ifclickmany1 == 0) {
            $(this).parent().addClass('active');
            $(this).parent().prev().val(1);
            calcProdSubNum();
            ifchooseornot1();
        } else {
            $(this).parent().removeClass('active');
            $(this).parent().prev().val(0);
            calcProdSubNum();
            ifchooseornot1();
        }
        calcProdSubTotal();
    });
    var sum1 = 0;
    var now_value1 = 0;

    function ifchooseornot1() {
        $(".trade_msg_box .dingdan .sex_radio").each(function() {
            now_value1 = $(this).prev().val();
            sum1 = $('.trade_msg_box .dingdan .sex_radio.active').length;
            if (sum1 == jdk1) {
                $(this).parents('.trade_msg_box').find('.thing .sex_radio').addClass('active');
                $(this).parents('.trade_msg_box').find('.thing input').val(1);
            } else {
                $(this).parents('.trade_msg_box').find('.thing .sex_radio').removeClass('active');
                $(this).parents('.trade_msg_box').find('.thing input').val(0);
            }
        });
    }


    var ifclickmany2;
    var jdk2 = $('.set_msg_box .dingdan').length;
    $('.shoppingcart .set_msg_box .dingdan .sex_radio i').click(function() {
        ifclickmany2 = $(this).parent().prev().val();
        if (ifclickmany2 == 0) {
            $(this).parent().addClass('active');
            $(this).parent().prev().val(1);
            calcProdSubNum();
            ifchooseornot2();
        } else {
            $(this).parent().removeClass('active');
            $(this).parent().prev().val(0);
            calcProdSubNum();
            ifchooseornot2();
        }
        calcProdSubTotal();
    });
    var sum2 = 0;
    var now_value2 = 0;

    function ifchooseornot2() {
        $(".set_msg_box .dingdan .sex_radio").each(function() {
            now_value2 = $(this).prev().val();
            sum2 = $('.set_msg_box .dingdan .sex_radio.active').length;
            if (sum2 == jdk2) {
                $(this).parents('.set_msg_box').find('.thing .sex_radio').addClass('active');
                $(this).parents('.set_msg_box').find('.thing input').val(1);
            } else {
                $(this).parents('.set_msg_box').find('.thing .sex_radio').removeClass('active');
                $(this).parents('.set_msg_box').find('.thing input').val(0);
            }
        });
    }

    //是否全选2016-05-10修改
    $('.shoppingcart .trade_msg_box .thing .sex_radio i').click(function() {
        ischooseall($(this));
    });
    $('.shoppingcart .set_msg_box .thing .sex_radio i').click(function() {
        ischooseall($(this));
    });

    function ischooseall(who) {
        var $_this = who;
        if ($_this.parent().hasClass('active')) {
            $_this.parent().removeClass('active');
            $_this.parents('.thing').parent().find('.sex_radio').removeClass('active');
            $_this.parents('.thing').parent().find('.sex_radio').prev().val(0);
            calcProdSubNum();
        } else {
            $_this.parent().addClass('active');
            $_this.parents('.thing').parent().find('.sex_radio').addClass('active');
            $_this.parents('.thing').parent().find('.sex_radio').prev().val(1);
            calcProdSubNum();
        }
        calcProdSubTotal();
    }

    //购物车订单删除
    $('.del_choose').click(function() {
        var selectAll = [];
        var ids = [];
        $(".dingdan .sex_radio").each(function(i) {
            var valNum = $(this).prev().val();
            if (valNum == 1) {
                selectAll.push(i);
                ids.push($(this).prev().attr('data-id'));
            }
        });
        if (selectAll.length == 0) {
            alert('请选择要删除的商品');
            return false;
        }
        showDelDingdan();
        $('.dingdan_del_out').click(function() {
            hideDelDingdan();
        });
        event.stopPropagation(); //阻止事件向上冒泡

        $('.del').click(function(event) {
            event.stopPropagation(); //阻止事件向上冒泡
        });
        $('.del .close').click(function() {
            hideDelDingdan();
        });
        $('.del .control .yes').unbind('click');
        $('.del .control .yes').click(function() {
            var id = ids.join(',');
            $.ajax({
                url: '/shop/goods/del_cart',
                type: 'POST',
                dataType: 'json',
                data: {
                    ids: id
                },
                success: function(res) {
                    hideDelDingdan();
                    alert(res.content, 0, 1500);
                    if (res.error == 0) {
                        $(".dingdan .sex_radio").each(function(i) {
                            var valNum = $(this).prev().val();
                            if (valNum == 1) {
                                $(this).parentsUntil('.dingdan').parent().remove();
                            }
                        });
                    }
                },
                error: function(res) {
                    hideDelDingdan();
                    alert('网络繁忙,请稍后再试');
                }
            });
        });
        $('.del .control .cancel').click(function() {
            hideDelDingdan();
        });
    });

    $('.delete_dingdan img').click(function(event) {
        var dingdan_line = $(this).parentsUntil('.dingdan').parent();
        var id = $(this).parent().attr('data-id');
        showDelDingdan();
        $('.dingdan_del_out').click(function() {
            hideDelDingdan();
        });
        event.stopPropagation(); //阻止事件向上冒泡

        $('.del').click(function(event) {
            event.stopPropagation(); //阻止事件向上冒泡
        });
        $('.del .close').click(function() {
            hideDelDingdan();
        });

        $('.del .control .yes').unbind('click');
        $('.del .control .yes').click(function(e) {
            $.ajax({
                url: '/shop/goods/del_cart',
                type: 'POST',
                dataType: 'json',
                data: {
                    ids: id
                },
                success: function(res) {
                    hideDelDingdan();
                    alert(res.content, res.url, 1500);
                    if (res.error == 0) {
                        dingdan_line.remove();
                    }
                },
                error: function(res) {
                    hideDelDingdan();
                    alert('网络繁忙,请稍后再试');
                }
            });
        });
        $('.del .control .cancel').click(function() {
            hideDelDingdan();
        });
    });

    function showDelDingdan() {
        $('.dingdan_del_out').css({
            'display': 'block'
        });
        $('.del').removeClass('hide');
        calcProdLine();
        calcProdSubNum();
        calcProdSubTotal();
    }

    function hideDelDingdan() {
        $('.dingdan_del_out').css({
            'display': 'none'
        });
        $('.del').addClass('hide');
        calcProdLine();
        calcProdSubNum();
        calcProdSubTotal();
    }

    //计算一行的总价钱
    function calcProdLine() {
        var prodLine = 0;
        $(".one_money").each(function() {
            var valString = $(this).html();
            var numString = $(this).next().find('input').val();
            prodLine = parseFloat(valString * numString).toFixed(2);
            $(this).next().next().html(prodLine);
        });
    };
    //计算商品总数量
    function calcProdSubNum() {
        var prodSubNum = 0;
        $(".dingdan .sex_radio").each(function() {
            var valNum = $(this).prev().val();
            if (valNum == 1) {
                $(this).parentsUntil('.dingdan').find('.dingdan_num input').each(function() {
                    var valString = $(this).val();
                    prodSubNum += parseInt(valString);
                });
            }
        });
        $(".all_num").html(prodSubNum);
    };
    //计算商品总价格
    function calcProdSubTotal() {
        var prodSubTotal = 0;
        var prodSubTotalFinal = 0;
        $(".dingdan .sex_radio").each(function() {
            var valNum = $(this).prev().val();
            if (valNum == 1) {
                var valString = $(this).parentsUntil('.dingdan').find('.total_money').text();
                prodSubTotal += parseFloat(valString);
                prodSubTotalFinal = parseFloat(prodSubTotal).toFixed(2);
            }
        });
        $(".money_width").html(prodSubTotalFinal);
    };

    calcProdLine();
    calcProdSubNum();

    var dingdan_num;
    $('.less').click(function() {
        var _this = $(this).next();
        dingdan_num = _this.val();
        var cart_id = _this.attr('data-id');
        if (dingdan_num > 1) {
            dingdan_num--;
            var type = $(this).attr('data-type');
            if (type == 'goods') {
                _this.val(dingdan_num);
                return false;
            }
            $.ajax({
                url: '/shop/goods/change_cart',
                type: 'POST',
                dataType: 'json',
                data: {
                    id: cart_id,
                    goods_num: dingdan_num,
                    act: 'del'
                },
                success: function(res) {
                    if (res.error == 0) {
                        _this.val(dingdan_num);
                        calcProdLine();
                        calcProdSubNum();
                        calcProdSubTotal();
                    } else {
                        alert(res.content, res.url);
                    }
                },
                error: function(res) {
                    alert('网络繁忙,请稍后再试');
                }
            });
        } else {
            return false;
        }
    });
    $('.more').click(function() {
        var _this = $(this).prev();
        dingdan_num = _this.val();
        var cart_id = _this.attr('data-id');
        dingdan_num++;
        var type = $(this).attr('data-type');
        if (type == 'goods') {
            _this.val(dingdan_num);
            return false;
        }
        $.ajax({
            url: '/shop/goods/change_cart',
            type: 'POST',
            dataType: 'json',
            data: {
                id: cart_id,
                goods_num: dingdan_num
            },
            success: function(res) {
                if (res.error == 0) {
                    _this.val(dingdan_num);
                    calcProdLine();
                    calcProdSubNum();
                    calcProdSubTotal();
                } else {
                    alert(res.content, res.url);
                }
            },
            error: function(res) {
                alert('网络繁忙,请稍后再试');
            }
        });
    });

    // 订单详情页
    //计算一行的总价钱
    function calc_Line_Total_Money() {
        var total_money = 0;
        $(".information_detail .one_money").each(function() {
            var valString = $(this).html();
            var numString = $(this).next().html();
            total_money = parseFloat(valString * numString).toFixed(2);
            $(this).next().next().html(total_money);
        });
    };

    function calc_Final_Money() {
        var final_money = 0;
        var trans_money = $('.information_detail .trans_money').html();
        var total_money = $('.information_detail .money_width').html();
        final_money += parseFloat(trans_money);
        final_money += parseFloat(total_money);
        final_money = parseFloat(final_money).toFixed(2);
        $('.information_detail .should_money_width').html(final_money);
    };

    function calcProdSubTotalOrder() {
        var prodSubTotal = 0;
        var prodSubTotalFinal = 0;
        $(".total_money2").each(function() {
            var valString = $(this).html();
            prodSubTotal += parseFloat(valString);
            prodSubTotalFinal = parseFloat(prodSubTotal).toFixed(2);
        });
        $(".money_width").html(prodSubTotalFinal);
        $(".should_money_width").html(prodSubTotalFinal);
    };
    calc_Line_Total_Money();
    calc_Final_Money();
    calcProdSubTotalOrder();
    /*会员中心*/

    $('.mem_list h1').click(function() {
        $(this).next().slideToggle('fast').toggleClass('no');
        if ($(this).next().hasClass('no')) {
            $(this).find('span img').attr({
                'src': '/Static/webroot/default/images/down.png'
            });
        } else {
            $(this).find('span img').attr({
                'src': '/Static/webroot/default/images/up.png'
            });
        }
    });

    /*注册*/
    $('.login_zc ul li').click(function() {
        var li_num = $(this).index();
        $(this).addClass('active').siblings().removeClass('active');
        $('.login_zc_change .lg-input').eq(li_num).removeClass('hide').siblings().addClass('hide');
    });
    /*体检指南*/
    $('.check_entrance_eng ul li a').click(function() {
        var eng_num = $(this).parent().index();
        $(this).parent().addClass('active').siblings().removeClass('active');
        $('.check_entrance_all .check_entrance_detail').eq(eng_num).removeClass('hide').siblings().addClass('hide');
    });
    $('.check_entrance_all .check_entrance_sub ul li').hover(function() {
        $(this).addClass('active').siblings().removeClass('active');
        if ($(this).hasClass('active')) {
            var city_num = $(this).index();
            $('.check_entrance_body_all .check_entrance_body').eq(city_num + 1).removeClass('hide').siblings().addClass('hide');
        }
    });

    /*商品详情*/
    $('.choose_list span').click(function() {
        $(this).addClass('active').siblings().removeClass('active');
    });
    $('.choose_change span').click(function() {
        var hidemoney = $(this).find('.hidemoney').val();
        var hidedel = $(this).find('.hidedel').val();
        var hidediscount = $(this).find('.hidediscount').val();
        $('.pro_all_money').find('.hidemoney').text(hidemoney);
        $('.pro_all_money').find('.hidedel').text('￥' + hidedel);
        $('.pro_all_money').find('.hidediscount').text(hidediscount + '折');
    });
    //套餐详情滚动

    $('.main_right .right_nav li').click(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var indexnav = $(this).index(); //从0开始
        function click_scroll() {
            var scroll_offset = $('.right_main').find('.pro_tab_show').eq(indexnav).offset().top;
            $("body,html").animate({
                scrollTop: scroll_offset - 50
            }, 0);
        }
        click_scroll();
    });

    //加入购物车
    //var buy_num = 0;
    $('.add_carts').click(function() {
        var buy_num = $('input[name=goods_num]').val();
        if (buy_num < 1) {
            alert('请输入正确的数量');
            return false;
        }
        var goods_id = $(this).attr('data-id');
        $.ajax({
            url: '/shop/goods/add_cart',
            type: 'POST',
            dataType: 'json',
            data: {
                goods_id: goods_id,
                goods_num: buy_num
            },
            success: function(res) {
                if (res.error == 0) {
                    var flyElm = $('.pro_pic img').clone().css('opacity', '0.7').addClass('add_img');
                    flyElm.css({
                        'z-index': 9000,
                        'display': 'block',
                        'position': 'absolute',
                        'top': 291,
                        'left': 200 + 'px',
                        'width': $('.pro_pic img').width() + 'px',
                        'height': $('.pro_pic img').height() + 'px'
                    });
                    $('body').append(flyElm);
                    flyElm.animate({
                        top: 0,
                        left: 1100 + 'px',
                        width: 50,
                        height: 50,
                        opacity: 0
                    }, 'slow');

                    if (res.data == 1) {
                        var cartnum = $('.yf-cart-num').text();
                        $('.yf-cart-num').text(parseInt(cartnum) + 1);
                    }

                    setInterval(function() {
                        $('.add_img').remove();
                    }, 2000);
                } else if (res.error == 2) {
                    alert(res.content);
                } else {
                    window.location.href = res.url;
                }
            },
            error: function(res) {
                alert('网络繁忙,请稍候');
            }
        });
        return false;
    });

    //nth-child不兼容问题
    $('.contentset .tijian_set .set_list .set_detail:nth-child(3n+1)').css({
        'margin-left': '0'
    });
    $('.contentall .tijian_set .set_list .set_detail').css({
        'margin-left': '16px'
    });
    $('.choose_box .choose_org .choose_all ul li:nth-child(8n+1)').css({
        'margin-left': '5px'
    });
    //    $('.choose_box .choose_org .top_hospital ul li:nth-child(2n+1)').css({
    //        'margin-left': '5px'
    //    });

    $('.shoppingcart table tr th:nth-child(1)').css({
        'width': '10%'
    });
    $('.shoppingcart table tr th:nth-child(2)').css({
        'width': '37%'
    });
    $('.information_detail .shoppingcart table tr th:nth-child(1)').css({
        'width': '37%'
    });
    $('.information_detail .shoppingcart table tr th:nth-child(2)').css({
        'width': '32%'
    });
    $('.mem_dingdan_detail .shoppingcart table tr th:nth-child(1)').css({
        'width': '17%'
    });
    $('.mem_dingdan_detail .shoppingcart table tr th:nth-child(2)').css({
        'width': '17%'
    });
    $('.social_right .content_say ul li:nth-child(even)').css({
        'margin-left': '9px'
    });
    $('.social_right .content_say ul li:nth-child(1)').css({
        'margin-top': '10px'
    });
    $('.social_right .content_say ul li:nth-child(2)').css({
        'margin-top': '10px'
    });
    $('.top_group ul li:nth-child(even)').css({
        'margin-left': '9px'
    });
    $('.social_right .social_read ul li:nth-child(1)').css({
        'margin-top': '0'
    });
    $('.social_right .social_read ul li:nth-child(even)').css({
        'margin-left': '0'
    });
    $('.social_right .social_read ul li:nth-child(2)').css({
        'margin-top': '0'
    });
    $('.after_know .after_know_item:nth-child(1)').css({
        'padding-top': '0'
    });
    $('.contentall .tijian_set .set_list .set_detail:nth-child(4n+1)').css({
        'margin-left': '0'
    });
    $('.pro_main .main_left .pro_show_list .show_list:nth-child(1)').css({
        'margin-top': '0'
    });
    $('.main_right .pro_tab_show .msg_jichu .pro_detail tr td').css({
        /*'border-left':'1px solid #ededed',*/
        /*'text-align':'center',*/
        /*fzh 2016/0802  */
    });
    $('.main_right .pro_tab_show .msg_jichu .pro_detail tr td:nth-child(1)').css({
        // 'width': '20%',
        /*'text-align':'center',*/
        /* 'border-left':'none'*/
    });
    $('.main_right .pro_tab_show .msg_jichu .pro_detail tr td:nth-child(2)').css({
        // 'width': '78%',
        /*'border-left':'1px solid #ededed'*/
    });

    $('.mem_order .mem_order_list li:nth-child(2) a').css({
        'border-left': 'none'
    });
    $('.mem_order .shoppingcart table tr th').css({
        'width': '10%'
    });
    $('.mem_order .shoppingcart table tr th:nth-child(1)').css({
        'width': '40%'
    });
    $('.mem_order .shoppingcart table tr th:nth-child(2)').css({
        'width': '10%'
    });
    $('.mem_order .shoppingcart .dingdan table tr th:nth-child(1)').css({
        'padding-left': '2%',
        'box-sizing': 'content-box'
    });
    $('.mem_order.mem_address .shoppingcart table tr th:nth-child(3)').css({
        'width': '280px'
    });
    $('.mem_order.mem_address .shoppingcart table tr th:nth-child(2)').css({
        'width': '115px'
    });
    $('.mem_order.mem_address .shoppingcart table tr th:nth-child(1)').css({
        'width': '100px'
    });
    $('.mem_order.mem_address .shoppingcart table tr th:nth-child(5)').css({
        'width': '160px'
    });
    $('.mem_order.mem_address .shoppingcart .dingdan table tr th:nth-child(1)').css({
        'padding-left': '0'
    });
    $('.org_change_list .contentset .tijian_set .set_list .set_detail:nth-child(3n+1)').css({
        'margin-left': '18px'
    });
    $('.classify_check .class_pic:nth-child(1)').css({
        'width': '60%'
    });
    $('.classify_check .class_pic:nth-child(2)').css({
        'width': '38%'
    });

    //选择框--egg改
    var more_click = true;
    $('.more_click').click(function() {
        if (more_click) {
            if (!$('.choose_detail').hasClass("hide")) {
                $('.choose_detail').addClass('hide');
                $(this).find('span').html('更多选项' + '<img src="/Static/webroot/default/images/select_down.png" class="full">');
                more_click = true;
            } else {
                $('.choose_detail.hide').removeClass('hide');
                $(this).find('span').html('收起' + '<img src="/Static/webroot/default/images/select_up.png" class="full">');
                more_click = false;
            }
        } else {
            $('.choose_detail').addClass('hide');
            $(this).find('span').html('更多选项' + '<img src="/Static/webroot/default/images/select_down.png" class="full">');
            more_click = true;
        }
    });

    $('.address_out .control .cancel').click(function() {
        $('.address_out').addClass('hide');
        return false;
    });
    $('.address_out a.close').click(function() {
        $(this).parent().parent().addClass('hide');
        return false;
    });
    $(document).on('click', '.change_address2', function() {
        showAddress();
        $('.change_address_box').click(function() {
            hideAddress();
        });
        event.stopPropagation(); //阻止事件向上冒泡

        $('.change_msg').click(function(event) {
            event.stopPropagation(); //阻止事件向上冒泡
        });
        $('.change_msg .change_close').click(function() {
            hideAddress();
        });
        $('.change_msg .submit').click(function() {
            hideAddress();
        });

        function showAddress() {
            $('.change_address_box').css({
                'opacity': '1',
                'display': 'block',
                'transition': 'opacity .15s linear',
                '-webkit-transition': 'opacity .15s linear'
            });
        }

        function hideAddress() {
            $('.change_address_box').css({
                'opacity': '0',
                'display': 'none',
                'transition': 'opacity .15s linear',
                '-webkit-transition': 'opacity .15s linear'
            });
        }
        //$('.change_address_box').removeClass('hide');
        var id = $(this).attr('id');
        var pct = $(".pct_msg" + id);
        var name = $(".name_msg" + id).text();
        var phone = $(".phone_msg" + id).text();
        var address = $(".address_msg" + id).text();
        var email = $(".email_msg" + id).text();
        var province_id = pct.attr("data-p");
        var province_name = pct.attr("data-pn");
        var city_id = pct.attr("data-c");
        var city_name = pct.attr("data-cn");
        var town_id = pct.attr("data-t");
        var town_name = pct.attr("data-tn");

        $("input[name='edit_name']").val(name);
        $("input[name='edit_phone']").val(phone);
        $("input[name='edit_address']").val(address);
        $("input[name='edit_email']").val(email);
        $("#act_edit").attr('data-id', id);

        set_province(province_id, province_name);
        set_city(province_id, city_id, 'Edit', city_name);
        set_town(city_id, town_id, 'Edit', town_name);
        return false;
    });
    $('.change_address_box .change_close').click(function() {
        $(this).parent().parent().parent().addClass('hide');
        return false;
    });
    $(document).click(function() {
        $('.address_out').addClass('hide');
        // $('.change_address_box').addClass('hide');
    });
    //切换城市
    $('.city_zimu .zimu li').click(function() {
        var currut = $(this).attr('data-currut');
        if (currut == 0) {
            return false;
        }
        var code = $(this).attr('data-code');
        $(this).addClass('active').siblings().removeClass('active');
        var indexset = $(this).index();
        $('.city_content').find('.city_item').siblings().slideUp('slow');
        $('.city_content').find('.city_item' + code).slideDown('slow');
    });
    $('.all_zimu').click(function() {
        $('.city_content .city_item').slideDown('slow');
        $('.city_zimu .zimu li.active').removeClass('active');
    });

    //机构分类切换    
    $(".select_more").click(function() {
        if ($(this).hasClass("down") === true) {
            $(this).removeClass("down").prev().animate({ height: '35px' });
            $(this).find('i').css({
                'background': 'url(/Static/webroot/default/images/select_down.png) no-repeat',
                'background-size': '8px'
            });
        } else {
            $(this).addClass("down").prev().animate({
                height: $(this).prev().children('ul').innerHeight() - 0
            });
            $(this).find('i').css({
                'background': 'url(/Static/webroot/default/images/select_up.png) no-repeat',
                'background-size': '8px'
            });
        }
    });
    $('.org_change ul li').click(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var indexset = $(this).index();
        $('.org_change_list_all').find('.org_change_list').eq(indexset).removeClass('hide').siblings().addClass('hide');
    });
    var choosed1;
    $('.select_all1 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed1 = $(this).text();
        if ($('.select1').length > 0) {
            $('.select1 span').text(choosed1);
            $('.select1 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select1 fl clear">' + '<span class="fl">' + choosed1 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });
    var choosed2;
    $('.select_all2 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed2 = $(this).text();
        if ($('.select2').length > 0) {
            $('.select2 span').text(choosed2);
            $('.select2 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select2 fl clear">' + '<span class="fl">' + choosed2 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });
    var choosed3;
    $('.select_all3 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed3 = $(this).text();
        if ($('.select3').length > 0) {
            $('.select3 span').text(choosed3);
            $('.select3 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select3 fl clear">' + '<span class="fl">' + choosed3 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });
    var choosed4;
    $('.select_all4 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed4 = $(this).text();
        if ($('.select4').length > 0) {
            $('.select4 span').text(choosed4);
            $('.select4 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select4 fl clear">' + '<span class="fl">' + choosed4 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });
    var choosed5;
    $('.select_all5 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed5 = $(this).text();
        if ($('.select5').length > 0) {
            $('.select5 span').text(choosed5);
            $('.select5 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select5 fl clear">' + '<span class="fl">' + choosed5 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });
    var choosed6;
    $('.select_all6 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed6 = $(this).text();
        if ($('.select6').length > 0) {
            $('.select6 span').text(choosed6);
            $('.select6 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select6 fl clear">' + '<span class="fl">' + choosed6 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });
    var choosed7;
    $('.select_all7 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed7 = $(this).text();
        if ($('.select7').length > 0) {
            $('.select7 span').text(choosed7);
            $('.select7 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select7 fl clear">' + '<span class="fl">' + choosed7 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });

    var choosed8;
    $('.select_all8 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed8 = $(this).text();
        if ($('.select8').length > 0) {
            $('.select8 span').text(choosed8);
            $('.select8 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select7 fl clear">' + '<span class="fl">' + choosed8 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });

    var choosed9;
    $('.select_all9 ul li').click(function() {
        $(this).parent().parent().prev().css({
            'background-color': '#dbdbdb'
        });
        $(this).addClass('active').siblings().removeClass('active');
        var $aType = $(this).find('a');
        var kind = $aType.attr('data-kind');
        var type = $aType.attr('data-type');
        var id = $aType.attr('data-id');
        choosed9 = $(this).text();
        if ($('.select9').length > 0) {
            $('.select9 span').text(choosed9);
            $('.select9 a').attr('data-type', type).attr('data-val', id);
        } else {
            $('.choosed ul').append('<li class="select7 fl clear">' + '<span class="fl">' + choosed9 + '</span>' + '<a class="yf-search-type close_c fl" data-type="' + type + '" data-val="' + id + '" data-kind="' + kind + '">x</a>' + '</li>');
        }
        if (kind == 1) {
            yf_check_url();
        }
    });

    $('.choosed').on('click', '.close_c', function() {
        var kind = $(this).attr('data-kind');
        $(this).parent().remove();
        if ($(this).parent().hasClass('select1')) {
            $('.select_all1').find('li.active').removeClass('active');
            $('.select_all1').prev().css({
                'background-color': '#0099ff'
            });
        } else if ($(this).parent().hasClass('select2')) {
            $('.select_all2').find('li.active').removeClass('active');
            $('.select_all2').prev().css({
                'background-color': '#0099ff'
            });
        } else if ($(this).parent().hasClass('select3')) {
            $('.select_all3').find('li.active').removeClass('active');
            $('.select_all3').prev().css({
                'background-color': '#0099ff'
            });
        } else if ($(this).parent().hasClass('select4')) {
            $('.select_all4').find('li.active').removeClass('active');
            $('.select_all4').prev().css({
                'background-color': '#0099ff'
            });
        } else if ($(this).parent().hasClass('select5')) {
            $('.select_all5').find('li.active').removeClass('active');
            $('.select_all5').prev().css({
                'background-color': '#0099ff'
            });
        } else if ($(this).parent().hasClass('select6')) {
            $('.select_all6').find('li.active').removeClass('active');
            $('.select_all6').prev().css({
                'background-color': '#0099ff'
            });
        } else if ($(this).parent().hasClass('select7')) {
            $('.select_all7').find('li.active').removeClass('active');
            $('.select_all7').prev().css({
                'background-color': '#0099ff'
            });
        }
        if (kind == 1) {
            yf_check_url();
        }
    });

    $('.choose_all ul li').click(function() {
        $(this).addClass('active').siblings().removeClass('active');
        yf_check_url();
    });

    var ck_rules = 0;
    var ck_phone = 0;
    var ck_username = 0;
    var ck_password = 0;
    var ck_re_password = 0;
    var ck_phone_cpt = 0;
    var code_succeed = 0;
    var ck_chk = 0;

    /*
     *验证用户名 函数
     */
    function chk_username() {
        $("#msg_username").hide();
        var username = $("#username").val();
        var reg = /^\w+$/;
        if (!reg.test(username)) {
            $("#msg_username").text("用户名不能包含字母、数字、下划线以外的字符");
            $("#msg_username").show();
            if (IE) {
                alert("用户名不能包含字母、数字、下划线以外的字符", 0, 1500);
            }
            ck_username = 0;
        } else {
            if (username.length < 3 || username.length > 16) {
                $("#msg_username").text("用户名不得少于3且不得大于 16个字符");
                $("#msg_username").show();
                if (IE) {
                    alert("用户名不得少于3且不得大于 16个字符", 0, 1500);
                }
                ck_username = 0;
            } else {
                $.post("/index.php?g=home&m=user&a=check_username", {
                        username: $("#username").val()
                    },
                    function(data, status) {
                        if (status == 'success') {
                            if (data.result == "error") {
                                $("#msg_username").text(data.msg);
                                $("#msg_username").show();
                                if (IE) {
                                    alert(data.msg, 0, 1500);
                                }
                                ck_username = 0;
                            } else {
                                ck_username = 1;
                                $("#msg_username").hide();
                            }

                        } else {
                            $("#msg_username").text("请求错误！");
                            $("#msg_username").show();
                            if (IE) {
                                alert("请求错误！", 0, 1500);
                            }
                            ck_username = 0;
                        }
                    }, 'json');
            }
        }
    }

    /*
     *验证密码函数
     */
    function chk_password() {
        $("#msg_password").hide();
        var password = $("#password").val();
        if (password.length < 6 || password.length > 16) {
            $("#msg_password").text("密码长度须为6-16个字符");
            $("#msg_password").show();
            if (IE) {
                alert("密码长度必须为6-16个字符", 0, 1500);
            }
            ck_password = 0;
        } else {
            var reg = /^\w+$/;
            if (!reg.test(password)) {
                $("#msg_password").text("密码不能包含特殊字符");
                $("#msg_password").show();
                if (IE) {
                    alert("密码不能 包含特殊字符", 0, 1500);
                }
                ck_password = 0;
            } else {
                ck_password = 1;
                $("#msg_password").hide();
            }
        }

    }

    /*
     *验证重复密码函数
     */
    function chk_re_password() {
        $("#msg_re_password").hide();
        var re_password = $("#re_password").val();
        var password = $("#password").val();
        if (password != re_password) {
            $("#msg_re_password").text("重复密码不正确");
            $("#msg_re_password").show();
            if (IE) {
                alert("重复密码不正确", 0, 1500);
            }
            ck_re_password = 0;
        } else {
            ck_re_password = 1;
            $("#msg_re_password").hide();
        }
    }
    /*
     *验证手机号码
     */
    function chk_phone() {
        $("#msg_phone").hide();
        var phone = $("#phone").val();
        if (phone.length != 11) {
            $("#msg_phone").text("该手机号码无效");
            $("#msg_phone").show();
            if (IE) {
                alert("该手机号码无效", 0, 1500);
            }
            ck_phone = 0;
        } else {
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: "/user/check_phone",
                data: {
                    phone: $("#phone").val(),
                },
                success: function(data) {
                    if (data.result == 'error') {
                        $("#msg_phone").text(data.msg);
                        $("#msg_phone").show();
                        if (IE) {
                            alert(data.msg, 0, 1500);
                        }
                        ck_phone = 0;
                    } else {
                        ck_phone = 1;
                        $("#msg_phone").hide();
                    }
                },
                error: function() {
                    alert("网络错误");
                    ck_phone = 0;
                }
            });
        }
    }
    /*
     *验证注册条例是否勾选
     */
    function chk_rules() {
        if ($("#check").prop('checked') == false) {
            alert("须同意注册条款才可注册！", 0, 1500);
            ck_rules = 0;
        } else {
            ck_rules = 1;
        }
    }

    /*
     * 验证手机验证码
     */
    function chk_phone_cpt() {
        cpt = $("#cpt_phone").val();
        if (cpt == '' || cpt == null) {
            $("#msg_cpt_phone").text("手机验证码不能为空！");
            $("#msg_cpt_phone").show();
            if (IE) {
                alert("手机验证码不能为空！", 0, 1500);
            }
            ck_phone_cpt = 0;
        } else {
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: "/user/check_phone_code",
                async: false,
                data: {
                    phone_code: cpt
                },
                success: function(data) {
                    if (data.result == 'error') {
                        $("#msg_cpt_phone").text(data.content);
                        $("#msg_cpt_phone").show();
                        if (IE) {
                            alert(data.content, 0, 1500);
                        }
                        ck_phone_cpt = 0;
                    } else {
                        ck_phone_cpt = 1;
                        $("#msg_cpt_phone").hide();
                    }
                },
                error: function() {
                    alert("发送失败", 0, 1500);
                    ck_phone_cpt = 0;
                }
            });
        }

    }


    $("#phone").change(function() {
        chk_phone();
    });
    $("#phone").blur(function() {
        chk_phone();
    });

    $("#password").change(function() {
        chk_password();
    });
    $("#password").blur(function() {
        chk_password();
    });

    $("#re_password").change(function() {
        chk_re_password();
    });
    $("#re_password").blur(function() {
        chk_re_password();
    });

    /**
     * 注册验证  
     */
    $("#reg").bind("click", function() {
        var obj = $("#reg");
        var data = obj.attr("data-type");
        register(obj, data);
    });

    function check() {
        $("#loading").css('display', 'block');
        chk_rules();
        if ((ck_rules == 1) && (ck_phone == 1) && (ck_password == 1) && (ck_re_password == 1)) {
            ck_chk = 1;
        } else {
            ck_chk = 0;
            if (ck_phone != 1) $("#msg_phone").show();
            if (ck_password != 1) $("#msg_password").show();
            if (ck_re_password != 1) $("#msg_re_password").show();
        }
    }
    /*
     *提交注册
     */
    function register(obj, data) {
        if (data == 'yes') {
            check();
            if (ck_chk == 1) {
                obj.attr('data-type', 'no').text('注册验证中...');
                phone = $("#phone").val();
                password = $("#password").val();
                re_password = $("#re_password").val();
                captcha = $("#captcha").val();
                cpt_phone = $("#cpt_phone").val();

                //加密部分 start
                var token = get_rand_token(); //获取登录token
                var login_data = {
                    "phone": phone,
                    "password": password,
                    "re_password": re_password,
                    "captcha": captcha,
                    "cpt_phone": cpt_phone
                }
                var login_info = JSON.stringify(login_data);
                var login_str = wu_aes_encrypt(login_info, token); //加密
                //加密部分 end

                $.post("/user/act_reg", {
                        "login_str": login_str
                    },
                    function(da, status) {
                        obj.attr('data-type', 'yes');
                        if (status == 'success') {
                            //data = eval('('+data+')');
                            $("#loading").css('display', 'none');
                            if (da.result != 'error') {
                                obj.text('注册成功');
                                setTimeout(function() {
                                    location.href = da.url;
                                }, 1500);
                            } else {
                                alert(da.msg);
                                obj.text('注册');
                            }
                        } else {
                            alert("网络繁忙", 0, 1500);
                            obj.text('重新注册');
                            return false;
                        }
                    }, 'json');
            } else {
                $("#loading").css('display', 'none');
                obj.attr('data-type', 'yes');
            }
        }
    }

    function hsTime(obj, wait) {
        if (wait == 0) {
            obj.attr('data-type', 'yes');
            obj.removeAttr("disabled").text('重发验证码');
        } else {
            obj.attr("disabled", true).text(wait + '秒');
            wait--;
            setTimeout(function() {
                hsTime(obj, wait)
            }, 1000);
        }
    }

    /**
     * 登录获取验证码
     */
    $(".lg-content .login_zc .lg-input-content").on('click', ".re_get_code", function() {
        if (ck_phone == 1) {
            $act = $(".re_get_code").attr('data-type');
            if ($act == "yes") {
                $(".re_get_code").attr('data-type', 'no');
                obj = $(".re_get_code");
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    url: "/user/get_phone_code2",
                    data: {
                        phone: $("#phone").val()
                    },
                    beforeSend: function(res) {
                        obj.text('发送中.');
                    },
                    success: function(data) {
                        if (data.err_msg == 'error') {
                            alert(data.content);
                        } else {
                            hsTime(obj, 120);
                            code_succeed = 1;
                        }
                    },
                    error: function() {
                        obj.text('重新获取');
                        alert("发送失败", 0, 1500);
                    }
                });
            }

        } else {
            alert("手机号码错误！", 0, 1500);
        }

    });

    /**
     * 登录验证
     */
    $("#lg_act").click(function() {
        var _this = $(this);
        $act = _this.attr("data-type");
        var remember = 0;
        var account = $("#lg_username").val();
        var pwd = $("#lg_pwd").val();
        var captcha = $("#captcha").val();
        checked = $('input[name=remember]').is(':checked');
        if (checked == true) {
            remember = 1;
        }
        if ($act == 'yes') {

            var token = get_rand_token(); //获取登录token
            var login_data = {
                "account": account,
                "pwd": pwd,
                "captcha": captcha
            }
            var login_info = JSON.stringify(login_data);
            var login_str = wu_aes_encrypt(login_info, token); //加密

            _this.attr("data-type", 'no').text('验证登录中...');
            $('#msg_lg').hide();
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: "/user/act_login",
                data: {
                    // account : $("#lg_username").val(),
                    // pwd : $("#lg_pwd").val(),
                    remember: remember,
                    // captcha : $("#captcha").val(),
                    login_str: login_str
                },
                success: function(data) {
                    if (data.error == 0) {
                        //alert('登录成功！', data.url, 1500);
                        _this.text('登录成功');
                        setTimeout(function() {
                            location.href = data.url;
                        }, 1500);
                    } else if (data.error == 2) {
                        $('#msg_lg').text(data.content);
                        $('#msg_lg').show();
                    } else {
                        $('#msg_lg').text("手机号或密码错误");
                        $('#msg_lg').show();
                        if (IE) {
                            alert("手机号或密码错误", 0, 1500);
                        }
                        $act = _this.attr("data-type", 'yes').text('重新登录');
                    }
                },
                error: function() {
                    alert("发送失败", 0, 1500);
                    $act = _this.attr("data-type", 'yes').text('重新登录');
                }
            });
        }
    });
    //获取随机token    lj20211029
    get_rand_token = function() {
            var token = "";
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: "/user/get_rand_token",
                async: false,
                success: function(result) {
                    token = result.data;
                },
                error: function() {
                    alert("系统出错3");
                }
            });
            return token;
        }
        //aes加密    lj20211029
    wu_aes_encrypt = function(str, key) {
            var key = CryptoJS.enc.Utf8.parse(key);
            var plaintText = str; // 明文
            var encryptedData = CryptoJS.AES.encrypt(plaintText, key, {
                mode: CryptoJS.mode.ECB,
                padding: CryptoJS.pad.Pkcs7
            });

            var enstr = encryptedData.ciphertext.toString();
            var hexstr = CryptoJS.enc.Hex.parse(enstr);
            var basestr = CryptoJS.enc.Base64.stringify(hexstr);
            return basestr;
        }
        /*20160702修改*/
    $('.lg-body').bind('keydown', function(event) {
        if (event.keyCode == 13) {
            $('#lg_act').trigger('click');
            $('#reg').trigger('click');
        }
    });
    /*
     * 添加收货地址
     */
    $("#addr_add_act").click(function() {
        var _this = $(this);
        $act = _this.attr("data-type");
        if ($act = 'yes') {
            var name = $("#name").val();
            var vprovince = $("input[name='provinceAdd']").val();
            var vcity = $("input[name='cityAdd']").val();
            var vtown = $("input[name='townAdd']").val();
            var address = $("#address").val();
            var phone = $("#phone").val();
            var email = $("#email").val();
            _this.attr("data-type", "no");
            $('#add_msg_err').hide();
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: "/user/add_addr",
                data: {
                    name: name,
                    province: vprovince,
                    city: vcity,
                    town: vtown,
                    address: address,
                    phone: phone,
                    email: email,
                },
                success: function(data) {
                    if (data.result == 'ok') {
                        alert('保存成功！');
                        setTimeout(function() {
                            location.reload();
                        }, 2000);
                        //get_addr();
                    } else {
                        alert(data.err_msg);
                        _this.attr("data-type", "yes");
                    }

                },
                error: function(err) {
                    alert("发送失败", 0, 1500);
                    _this.attr("data-type", "yes");
                }
            });
        }

    });
    /*2016-05-10新增*/
    /*地址弹框*/
    $('.add_news_address').click(function(event) {
        showAddress();
        $('.change_address_box').click(function() {
            hideAddress();
        });
        event.stopPropagation(); //阻止事件向上冒泡

        $('.change_msg').click(function(event) {
            event.stopPropagation(); //阻止事件向上冒泡
        });
        $('.change_msg .change_close').click(function() {
            hideAddress();
        });
        $('.change_msg .submit').click(function() {
            //hideAddress();
            var _this = $(this);
            var type = _this.attr('data-type');
            if (type == 'yes') {
                var name = $('input[name=name]').val();
                if (name == '' || name == null || name == undefined) {
                    alert('请输入收货人姓名', 0, 1500);
                    return false;
                }
                var province = $('input[name=province]').val();
                if (province == 0 || province == '' || province == null || province == undefined) {
                    alert('请选择收货省份', 0, 1500);
                    return false;
                }
                var city = $('input[name=city]').val();
                if (city == 0 || city == '' || city == null || city == undefined) {
                    alert('请选择收货城市', 0, 1500);
                    return false;
                }
                var town = $('input[name=town]').val();
                if (town == 0 || town == '' || town == null || town == undefined) {
                    alert('请选择收货县区', 0, 1500);
                    return false;
                }
                var address = $('input[name=addressText]').val();
                if (address == '' || address == null || address == undefined) {
                    alert('请输入收货详细地址', 0, 1500);
                    return false;
                }
                var phone = $('input[name=phone]').val();
                if (phone == '' || phone == null || phone == undefined) {
                    alert('请输入手机号码', "#", 1500);
                    return false;
                }
                var email = $('input[name=email]').val();
                _this.attr('data-type', 'no').text('提交中');
                $.ajax({
                    url: '/user/add_addr',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        name: name,
                        province: province,
                        city: city,
                        town: town,
                        address: address,
                        phone: phone,
                        email: email
                    },
                    success: function(res) {
                        if (res.result == 'ok') {
                            setTimeout(function() {
                                location.reload();
                            }, 2000);
                        } else {
                            alert(res.err_msg, 0, 1500);
                        }
                        _this.attr('data-type', 'yes').text('保存收货人信息');
                    },
                    error: function(res) {
                        alert('网络繁忙,请稍后再试', 0, 1500);
                        _this.attr('data-type', 'yes').text('保存收货人信息');
                    }
                });
            }
        });

        function showAddress() {
            $('.change_address_box').css({
                'opacity': '1',
                'display': 'block',
                'transition': 'opacity .15s linear',
                '-webkit-transition': 'opacity .15s linear'
            });
        }

        function hideAddress() {
            $('.change_address_box').css({
                'opacity': '0',
                'display': 'none',
                'transition': 'opacity .15s linear',
                '-webkit-transition': 'opacity .15s linear'
            });
        }
    });

    $('.change_address').click(function(event) {
        showAddress();
        $('.change_address_box').click(function() {
            hideAddress();
        });
        event.stopPropagation(); //阻止事件向上冒泡

        $('.change_msg').click(function(event) {
            event.stopPropagation(); //阻止事件向上冒泡
        });
        $('.change_msg .change_close').click(function() {
            hideAddress();
        });
        $('.change_msg .submit').click(function() {
            hideAddress();
        });

        function showAddress() {
            $('.change_address_box').css({
                'opacity': '1',
                'display': 'block',
                'transition': 'opacity .15s linear',
                '-webkit-transition': 'opacity .15s linear'
            });
        }

        function hideAddress() {
            $('.change_address_box').css({
                'opacity': '0',
                'display': 'none',
                'transition': 'opacity .15s linear',
                '-webkit-transition': 'opacity .15s linear'
            });
        }
    });

    /*删除弹框*/
    $(document).on("click", '.del_address', function(event) {
        var user_address = $(this).parents('.dingdan');
        var obj = this;
        showDel();
        $('.dingdan_del_out').click(function() {
            hideDel();
        });
        event.stopPropagation(); //阻止事件向上冒泡

        $('.del').click(function(event) {
            event.stopPropagation(); //阻止事件向上冒泡
        });
        $('.del .close').click(function() {
            hideDel();
        });
        $('.del .control .yes').unbind('click');
        $('.del .control .yes').click(function() {
            var id = $(obj).attr('id');
            hideDel();
            del_address(obj, id);
            user_address.remove();
        });
        $('.del .control .cancel').click(function() {
            hideDel();
        });

        function showDel() {
            $('.dingdan_del_out').css({
                'display': 'block'
            });
            $('.del').removeClass('hide');
        }

        function hideDel() {
            $('.dingdan_del_out').css({
                'display': 'none'
            });
            $('.del').addClass('hide');
        }
    });

    /*重写alert*/
    window.alert = function(txt, url, time) {
        var alertFram = document.createElement("DIV");
        var af = [];
        var alertflag = 0;
        alertFram.id = "alertFram" + alertflag;
        alertFram.style.position = "fixed";
        alertFram.style.width = "100%";
        alertFram.style.height = "100%";
        alertFram.style.left = "0";
        alertFram.style.top = "0";
        alertFram.style.background = "rgba(0,0,0,0.4)";
        alertFram.style.textAlign = "center";
        alertFram.style.zIndex = "10001";
        alertFram.className = "cart_big_box";
        strHtml = "<div style=\"position:absolute;left:44%;top:30%;margin-left:-100px;margin-top:-25px;width:360px;background-color:#ccc;text-align:center;z-index:10001;\" class=\"cart_box\">\n"
        strHtml += "<div style=\"padding: 0 15px;height: 35px;line-height: 35px;color: #fff;background-color: #0099ff;border-bottom: 1px solid #e5e5e5;\">\n";
        strHtml += "<span style=\"float:left;color:#fff;height:35px;line-height:35px;font-size:14px;\">" + "提示" + "</span>\n";
        strHtml += "<div style=\"color:#fff;float:right;cursor: pointer;margin: 9.5px 0;width: 16px;height: 16px;background-color: #fff;border-radius: 100%;text-shadow: none;line-height: 16px;color: #939292;font-size: 16px;font-weight: normal;opacity: 1;\">\n"
        strHtml += "<span style=\"text-shadow: none;line-height: 16px;color: #939292;font-size: 16px;font-weight: normal;\" class=\"close\">" + "×" + "</span>\n";
        strHtml += "</div>\n";
        strHtml += "</div>\n";
        strHtml += "<div style=\"background-color:#fff;border:1px solid #efefef;margin:0px;padding:0px;width:100%;height:100%;\">\n";
        strHtml += "<p style=\"color: #000000;margin: 0;text-align: center;font-size: 17px;line-height: 54px;padding-top: 15px;padding-left: 15px;padding-right: 15px;padding-bottom: 0;\">" + txt + "</p>\n";
        if (time != null || time != undefined) {
            time = parseInt(time);
            if (url) {
                strHtml += "正在自动跳转...";
                setTimeout("location.href = '" + url + "';", time);
            } else {
                setTimeout("$('.cart_big_box').remove();", time);
            }

        }
        //strHtml += "<a href=\"javascript:;\" style=\"color:#fff;background-color:#0099ff;width:75px;margin-bottom:15px;height:25px;line-height:25px;margin-top:20px;\" class=\"yes\">"+"确定"+"</a>\n";
        strHtml += "<br><br></div>\n";
        strHtml += "</div>\n";
        alertFram.innerHTML = strHtml;
        document.body.appendChild(alertFram);
        af.push(alertflag);
        alertflag += 1;

        $('.cart_box .close').click(function() {
            $('.cart_big_box').remove();
        });
        $('.cart_box .yes').click(function() {
            $('.cart_big_box').remove();
            if (url) {
                location.href = url;
            }
        });
    };

    /*
     * 保存收货地址
     */
    $("#act_edit").click(function() {
        var _this = $(this);
        $act = _this.attr("data-type");
        if ($act = 'yes') {
            var id = _this.attr("data-id");
            var name = $("input[name='edit_name']").val();
            var vprovince = $("input[name='provinceEdit']").val();
            var vcity = $("input[name='cityEdit']").val();
            var vtown = $("input[name='townEdit']").val();
            var address = $("input[name='edit_address']").val();
            var phone = $("input[name='edit_phone']").val();
            var email = $("input[name='edit_email']").val();
            $act = _this.attr("data-type", "no");
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: "/user/edit_addr",
                data: {
                    id: id,
                    name: name,
                    province: vprovince,
                    city: vcity,
                    town: vtown,
                    address: address,
                    phone: phone,
                    email: email,
                },
                success: function(data) {
                    if (data.result == 'ok') {
                        $('.change_address_box').addClass('hide');
                        alert('保存成功！', 0, 2000);
                        setTimeout(function() {
                            location.reload();
                        }, 2000);
                    } else {
                        alert(data.err_msg, 0, 2000);
                    }
                    _this.attr("data-type", "yes");
                },
                error: function(err) {
                    alert("发送失败", 0, 1500);
                    _this.attr("data-type", "yes");
                }
            });
        }

    });

    /*
     * 设置默认收货地址
     */
    $(document).on('click', ".def_address", function() {
        var _this = $(this);
        $act = _this.attr("data-type");
        if ($act = 'yes') {
            var id = _this.attr("id");
            _this.attr("data-type", "no");
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: "/user/set_def_addr",
                data: {
                    id: id,
                },
                success: function(data) {
                    if (data.result == 'ok') {
                        alert('设置成功！', 0, 1500);
                        setTimeout(function() {
                            location.reload();
                        }, 1500);
                    } else {
                        alert(data.err_msg, 0, 1500);
                    }
                    _this.attr("data-type", "yes");
                },
                error: function(err) {
                    alert("发送失败", 0, 1500);
                    _this.attr("data-type", "yes");
                }
            });
        }

    });

    /*
     * 删除收货地址
     */
    function del_address(obj, id) {
        $act = $(obj).attr("data-type");
        if ($act = 'yes') {
            $act = $(obj).attr("data-type", "no");
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: "/user/del_addr",
                data: {
                    id: id,
                },
                success: function(data) {
                    if (data.result == 'ok') {
                        alert('删除成功！', 0, 1500);
                        get_addr();
                    } else {
                        alert(data.err_msg, 0, 1500);
                    }
                    $(obj).attr("data-type", "yes");
                },
                error: function(err) {
                    alert("发送失败", 0, 1500);
                    $(obj).attr("data-type", "yes");
                }
            });
        }

    }


    /*20160604*/
    $('.biaoqian2 li').click(function() {
        if ($(this).hasClass('active')) {
            $(this).removeClass('active');
        } else {
            $(this).addClass('active');
        }

    });
    /*20160614*/
    $('.list_item li:nth-child(1) .list_title').css({
        'color': '#0099ff'
    });
    $('.list_item li:nth-child(2) .list_title').css({
        'color': '#0099ff'
    });
    $('.list_item li:nth-child(3) .list_title').css({
        'color': '#0099ff'
    });
    $('.social_right1 .tiezi li').hover(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var tie = $(this).index(); //从0开始
        $('.social_list').find('.list_item').eq(tie).removeClass('hide').siblings().addClass('hide');
    });
    var mySwiperTopic = new Swiper('.swiper-container-topic', {
        autoplay: 3000,
        loop: true
    });
    /*$('.first_one ul li').click(function() {
        var p_num = $(this).find('a span').text();
        if (!$(this).hasClass('active')) {
            $(this).addClass('active');
            p_num++;
            $(this).find('a span').text(p_num);
            $(this).find('a').css({
                'color': '#0099ff'
            });
        }else{
            $(this).removeClass('active');
            p_num--;
            $(this).find('a span').text(p_num);
            $(this).find('a').css({
                'color': 'rgb(129,129,129)'
            });
        }
    });*/

    //字数限制
    var txtobj = {
        divName: "p_topic", //外层容器的class
        textareaName: "topic_title", //textarea的class
        numName: "limit_num", //数字的class
        num: 25 //数字的最大数目
    }
    var textareaFn = function() {
        //定义变量
        var $onthis; //指向当前
        var $divname = txtobj.divName; //外层容器的class
        var $textareaName = txtobj.textareaName; //textarea的class
        var $numName = txtobj.numName; //数字的class
        var $num = txtobj.num; //数字的最大数目

        function isChinese(str) { //判断是不是中文
            var reCh = /[u00-uff]/;
            return !reCh.test(str);
        }

        function numChange() {
            var strlen = 0; //初始定义长度为0
            var txtval = $.trim($onthis.val());
            for (var i = 0; i < txtval.length; i++) {
                if (isChinese(txtval.charAt(i)) == true) {
                    strlen = strlen + 2; //中文为2个字符
                } else {
                    strlen = strlen + 2; //英文一个字符
                }
            }
            strlen = Math.ceil(strlen / 2); //中英文相加除2取整数
            if ($num - strlen < 0) {
                $par.html("超出<span style='color:red;' class=" + $numName + ">" + Math.abs($num - strlen) + "</span>字"); //超出的样式
            } else {
                $par.html("还可以输入<span class=" + $numName + ">" + ($num - strlen) + "</span>个字"); //正常时候
            }
            $b.html($num - strlen);
        }
        $("." + $textareaName).bind("focus", function() {
            $b = $(this).parents("." + $divname).find("." + $numName); //获取当前的数字
            $par = $b.parent();
            $onthis = $(this); //获取当前的textarea
            var setNum = setInterval(numChange, 500);
        });
    }
    textareaFn();

    $('.shoppingcart.tie table tr th:nth-child(1)').css({
        'width': '50%'
    });
    $('.shoppingcart.tie table tr th:nth-child(2)').css({
        'width': '10%'
    });
    $('.shoppingcart.tie table tr th:nth-child(3)').css({
        'width': '15%'
    });
    $('.shoppingcart.tie table tr th:nth-child(4)').css({
        'width': '10%'
    });
    $('.shoppingcart.tie table tr th:nth-child(5)').css({
        'width': '15%'
    });
    $('.shoppingcart.hui table tr th:nth-child(1)').css({
        'width': '65%'
    });
    $('.shoppingcart.hui table tr.all th').css({
        'width': '100%'
    });
    $('.pailie li').hover(function() {
        $(this).addClass('active').siblings().removeClass('active');
        var tie = $(this).index(); //从0开始
        $('.list_all').find('.list_item').eq(tie).removeClass('hide').siblings().addClass('hide');
    });

    $('.sex-choose label span').click(function() {
        if (!$(this).hasClass('sex-selected')) {
            $(this).addClass('sex-selected').parent().siblings().find('span').removeClass('sex-selected');
            var sex = $(this).parent().text();
            $(this).parent().parent().find('input').val(sex);
        }
    });
    $('.marry-choose label span').click(function() {
        if (!$(this).hasClass('sex-selected')) {
            $(this).addClass('sex-selected').parent().siblings().find('span').removeClass('sex-selected');
            var marry = $(this).parent().text();
            $(this).parent().parent().find('input').val(marry);
        }
    });
    $('.reserved-btn').click(function() {

        $('input[name=name]').val('');
        $('input[name=sex1]').val('');
        $('input[name=manid]').val('');
        $('input[name=marry]').val('');
        $('input[name=time]').val('');
        $('input[name=phone]').val('');
        $(".d_organization").remove();
        $('.change_address_box2').css({
            'opacity': '1',
            'display': 'block',
            'transition': 'opacity .15s linear',
            '-webkit-transition': 'opacity .15s linear'
        });
        //团购的预约为3
        var status = $(this).attr("data-status");
        var gid = $(this).attr("good-id");
        $(".submit2").attr("data-status", 2);
        $('.submit2').attr('data-change', 0);
        _this = $(this);
        var goodid = _this.attr('good-id');
        var orderid = _this.attr('order-id');
        var ogid = _this.attr('og-id');
        $('input[name=goodid]').val(goodid);
        $('input[name=orderid]').val(orderid);
        $('input[name=ogid]').val(ogid);
        var change = _this.attr('data-type');
        var organize = "";
        if (change == 'change') {

            var id = _this.attr('data-id');
            $('input[name=appointment_id]').val();
            //        	_this.attr('data-type', 'no');
            $.ajax({
                url: '/user/get_appointment_info',
                type: 'POST',
                dataType: 'json',
                async: false,
                data: {
                    id: id
                },
                success: function(res) {
                    console.log(res);
                    if (res.error == 1) {
                        alert("拉取数据 失败！ " + res.content);
                        _this.attr('data-type', 'change');
                        $('.change_address_box2').css({
                            'display': 'none'
                        });
                        return false;
                    }
                    $('.submit2').attr('data-change', 1);
                    $('input[name=name]').val(res.data.name);
                    $('input[name=sex1]').val(res.data.sex);
                    var sex = res.data.sex == '男' ? 0 : 1; //修改男0女1 lijing 20170410
                    $('input[name=sex1]').parent().find('label').each(function(i) {
                        $(this).find('span').removeClass('sex-selected');
                        if (sex == i) {
                            $(this).find('span').addClass('sex-selected');
                        }
                    });
                    $('input[name=marry]').val(res.data.marry);
                    var marray = res.data.marry == '未婚' ? 0 : 1;
                    $('input[name=marry]').parent().find('label').each(function(i) {
                        $(this).find('span').removeClass('sex-selected');
                        if (marray == i) {
                            $(this).find('span').addClass('sex-selected');
                        }
                    });
                    if (status == 3 || status == 8) { //添加特价商品显示机构  lijing 20170327
                        organize = res.data.organize;
                        //                                    $(".d_type").find("option").each(function(){
                        //                                       if($(this).text()==res.data.organize){
                        //                                           $(this).attr("selected",true);
                        //                                       } 
                        //                                    });
                    }
                    $('input[name=time]').val(res.data.time);
                    $('input[name=phone]').val(res.data.phone);
                    $('input[name=manid]').val(res.data.manid);
                    $('input[name=appointment_id').val(res.data.id);
                    var suc = _this.attr('succeed-type');
                    if (suc == 1) {
                        $('.submit2').hide();
                        $('input[name=phone]').attr("readonly", "readonly");
                        $('input[name=manid]').attr("readonly", "readonly");
                        $('input[name=marry]').attr("readonly", "readonly");
                        $('input[name=sex1]').attr("readonly", "readonly");
                        $('input[name=name]').attr("readonly", "readonly");
                    } else {
                        $('input[name=phone]').removeAttr("readonly");
                        $('input[name=manid]').removeAttr("readonly");
                        $('input[name=marry]').removeAttr("readonly");
                        $('input[name=sex1]').removeAttr("readonly");
                        $('input[name=name]').removeAttr("readonly");
                    }
                },
                error: function(res) {
                    alert('网络繁忙');
                    _this.attr('data-type', 'change');
                }
            });
        }
        var org_id = '';
        if (status == 3 || status == 8) { //添加特价商品（8）判断 	lijing 20170327
            $(".submit2").attr("data-status", status);
            var html = '<div class="search-dq clear d_organization"><span class="fl name">机构选择：</span><div class="search_detail radio-choose marry-choose fl"><select class="d_type form-control2 mar-r-10" name="organize" style="width:100%"><option value="0">请选择</option>';
            $.ajaxSettings.async = false;
            $.post("/home/user/get_organize", { id: gid }, function(res) {
                if (res.error == 1) {

                } else {
                    $(".d_type").empty();
                    if (res.data.length > 0) {
                        for (i = 0; i < res.data.length; i++) {
                            html += '<option value=' +
                                res.data[i].id + '>' //机构id lqx 20180226
                                +
                                res.data[i].name + '</option>';
                        }
                    }
                    html += "</select></div></div>";
                    $(".d_marry").after(html);
                    $(".d_type").find("option").each(function() {
                        if (isNaN(organize)) { //保存的是机构名 lqx 20180226
                            if ($(this).text() == organize) {
                                $(this).attr("selected", true);
                            }
                        } else { //保存的是机构id lqx 20180226
                            if ($(this).attr('value') == organize) {
                                $(this).attr("selected", true);
                                org_id = $(this).attr('value'); //特价团购修改
                            }
                        }
                    });

                }
            }, "json");
            $.ajaxSettings.async = true;
        } else {
            org_id = $(this).attr("org-id");
        }
        //机构预约时间控制 lqx 20190226
        if (org_id) {
            $.post('/home/user/get_org_info', { id: org_id },
                function(res) {
                    if (res.error == 0) {
                        var min_date = res.data.min_date
                            //获取当前是星期几 lqx 20190719
                        var current = new Date();
                        var day = current.getDay();
                        var hour = current.getHours();
                        if ((day == 5 && hour >= 12) || day == 6) {
                            var min_day = 9 - day;
                            if (min_day > min_date) {
                                min_date = min_day;
                            }
                        } else if (day == 0) { //星期天
                            var min_day = 2;
                            if (min_day > min_date) {
                                min_date = min_day;
                            }
                        }
                        $('input[name="min_date_num"]').val(min_date);
                        $('input[name="max_date"]').val(res.data.max_date);
                        $('input[name="disabledays"]').val(res.data.disabledays);
                        $('input[name="disabledates"]').val(res.data.disabledates);
                    } else {
                        $('input[name="min_date_num"]').val("");
                        $('input[name="max_date"]').val("");
                        $('input[name="disabledays"]').val("");
                        $('input[name="disabledates"]').val("");
                    }
                }, 'json');
        }

        $('.reserved_close').click(function() {
            $('.change_address_box2').css({
                'opacity': '0',
                'display': 'none',
                'transition': 'opacity .15s linear',
                '-webkit-transition': 'opacity .15s linear'
            });
        });
    });
    $('.mem_order.my_order .shoppingcart .dingdan table tr th:nth-child(1)').css({
        'padding-top': '15px',
        'padding-bottom': '15px'
    });

    $('.mem_order.my_order .shoppingcart .dingdan table tr th:nth-child(1)').css({
        'padding-top': '15px',
        'padding-bottom': '15px'
    });
    //2016-07-21
    $('.wx-pay-body').hover(function() {
        $('.wx-example').css({
            'opacity': '1',
            'right': '-310px'
        });
    }, function() {
        $('.wx-example').css({
            'opacity': '0',
            'right': '-290px'
        });
    });
    var wait = 90;
    var t;
    var timer_is_on = 0;

    function time() {
        if (wait == 0) {
            $('.wx-pay-get-code').removeClass('hide');
            $('.wx-code-time').html('<p class="b_blue">' + '二维码已过期，请重新获取二维码。' + '</p>')
        } else {
            wait--;
            $('.code-time').text(wait);
            t = setTimeout(function() { time() }, 1000)
        }
    }

    function doTimer() {
        if (!timer_is_on) {
            timer_is_on = 1;
            time();
        }
    }

    function stopCount() {
        clearTimeout(t);
        timer_is_on = 0;
        wait = 90;
    }
    $('.pay_platform img').click(function(event) {
        if ($(this).attr("data-type") == "we") {
            $('.change_address_box').css({
                'opacity': '1',
                'display': 'block'
            });
            time();
        }
    });
    $('.wx-pay-box .change_close').click(function(event) {
        $('.change_address_box').css({
            'opacity': '0',
            'display': 'none'
        });
        stopCount();

        // 20160719
        $('.mem_order.my_order .shoppingcart .dingdan table tr th:nth-child(1)').css({
            'padding-top': '15px',
            'padding-bottom': '15px'
        });
    });
    $('.group-buy-product-img-box').hover(function() {
        $(this).find('.group-buy-product-intro').siblings('.group-buy-product-intro').stop(true).animate({ 'top': '100%' }, 10);
        $(this).find('.group-buy-product-intro').stop(true).animate({ 'top': '0' }, 300);
    }, function() {
        $(this).find('.group-buy-product-intro').stop(true).animate({ 'top': '100%' }, 300);
    });
    $('#goods-view-contactbox').hover(function() {
        $(this).find('.goods-view-contact-hide').addClass('goods-view-contact-hide-a');
    }, function() {
        $(this).find('.goods-view-contact-hide').removeClass('goods-view-contact-hide-a');
    });

    /*20161223clm*/
    $('.btn-add-more').click(function() {
        var childs = $('.upload-wrapper').children('.upload-box.hide').length;
        var i;
        for (i = 2; i <= 5; i++) {

            if ($('#unique_id' + i).is(':hidden')) {
                $('#unique_id' + i).removeClass('hide');
                return;
            }
        }
        //$('.btn-add-more').addClass('hide');
        $('.btn-add-more').css("background-color", "#ccc");
        //以下注释原来代码  lijing 20170403
        /*
        var child = 5-childs+1;
        if (child > 1) {
            if (child == 5) {
                $('.btn-add-more').addClass('hide');
            }
            $('#unique_id'+child).removeClass('hide');
        }
		*/
    });
});